import { adjustWebSocketUrl } from '@/utils/adjustWebSocketUrl';
import { computed } from 'vue';

interface UseImagePreviewOptions {
  serverUrl?: string;
}

export function useImagePreview(imagePath: string | undefined, options: UseImagePreviewOptions = {}) {
  const { serverUrl } = options;

  const imageList = computed(() => {
    if (!imagePath) return [];
    return imagePath.split(',').map(path => 
      serverUrl ? adjustWebSocketUrl(path.trim(), serverUrl) : path.trim()
    );
  });

  const previewImage = computed(() => {
    return imageList.value[0] || '';
  });

  return {
    imageList,
    previewImage
  };
}

export default useImagePreview;
